/*
 * @Author: jiu yin
 * @Date: 2024-04-09 11:50:34
 * @LastEditTime: 2024-04-10 10:50:12
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \web-smart-tour\src\hooks\navigator\index.js
 * jiu
 */

import { go } from '@/router/index.js';
// const go = router.go

// go('/pages/goods/groupon', {
//   id: state.data.goods.id,
//   activity_id: state.data.goods.activity.id,
// })

export function navigateTo(
	url,
	success = () => {
		console.log('go success');
	}
) {
	console.log('[  ] >', url);
	go(
		url,
		{},
		{
			success: success,
		}
	);
	// uni.navigateTo({
	// 	url,
	// 	success
	// });
}
//关闭当前页面，跳转到应用内的某个页面。
export function redirectTo(url, success = () => {}) {
	go(
		url,
		{},
		{
			redirect: true,
			success: success,
		}
	);
	// uni.redirectTo({
	// 	url,
	// 	success
	// });
}
//关闭所有页面，打开到应用内的某个页面。
export function reLaunch(url, success = () => {}) {
	uni.reLaunch({
		url,
		success,
	});
}
//跳转到 tabBar 页面，并关闭其他所有非 tabBar 页面。
export function switchTab(url, success = () => {}) {
	go(
		url,
		{},
		{
			success: success,
		}
	);

	// uni.switchTab({
	// 	url,
	// 	success
	// });
}
//关闭当前页面，返回上一页面或多级页面
export function navigateBack(num = 1, success = () => {}) {
	uni.navigateBack({
		data: num,
		success,
	});
}

export function openLocation(option = { latitude: '', longitude: '', address: '', title: '' }) {
	const { latitude = '', longitude = '', address = '', title = '' } = option;
	console.log('openLocation', option);
	uni.openLocation({
		latitude: Number(latitude), // 目标地点的纬度，浮点数，范围为-90~90
		longitude: Number(longitude), // 目标地点的经度，浮点数，范围为-180~180
		scale: 18, // 缩放比例，范围5~18
		name: title ? title : address, // 位置名
		address: address, // 详细地址，选填
		success() {
			console.log('导航启动成功');
		},
		fail(error) {
			console.log('导航启动失败', error);
		},
	});
}
